<?php
	class Listdeal extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			if (!isset($_SESSION)) {
			    session_start();
			    session_regenerate_id();
			}
			$this->load->helper("url");
			
		}
		public function index()
		{
			$data=array();
			$this->load->model("mcategory");
			$data['list_category']=$this->mcategory->list_category();
			if(isset($_REQUEST['m_namedeal'])){
				$m_start=$_REQUEST['m_start'];
				$m_end=$_REQUEST['m_end'];
				$m_namedeal=$_REQUEST['m_namedeal'];
				$m_category=$_REQUEST['m_category'];
				$this->load->model("mdeal");
				$data['list_deal']=$this->mdeal->list_deal_search($m_start,$m_end,$m_namedeal,$m_category);
				$data['action']='list_deal';
			}else{
				$cid=0;
				if(isset($_REQUEST['cid']))
					$cid=$_REQUEST['cid'];
				$this->load->model("mdeal");
				$data['list_deal']=$this->mdeal->list_deal($cid);
				$data['action']='list_deal';
			}
			$this->load->view("deal_template", $data);
		}
		public function delete(){
			$id_deal=trim($_REQUEST['did']);
			$this->load->model("mdeal");
			$this->mdeal->delete_deal($id_deal);
			
			echo '<script>
						window.location.assign("'.$_SESSION['linkdeal'].'");
						</script>';
		}
		
		
	}
?>